<?php

/**
 * MediaRecommend
 * Copyright (C) 2008 Brian Lukis and Others
 *
 * Some modules included.  Copyright & licensing noted in their own 
 * directories.
 *
 * This file is the main web entry point for MediaRecommend.
 *
 * ----------
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('include/inc_database.php');
require_once('include/inc_useraccount.php');
require_once('include/inc_recommendation.php');

// Open DB connection.
$dbobj = new DatabaseObject();
$dbobj->OpenConnection();

$auth = new UserAccount();

if ($_POST['username'] != "") {
	Header("Location: user.php?user=" . $_POST['username']);
	exit();
}

$PAGE_LENGTH = 20;
$page = $_GET['page'];
if (!$page)
	$page = 1;
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?=SiteConst('site_name')?></title>

<link rel="shortcut icon" href="images/favicon.gif" type="image/x-icon">
<meta name="viewport" content="width=700"/>

<link rel="alternate" type="application/rss+xml" title="<?=SiteConst('site_name')?> - <?=$username?>" href="rec_feed.php?all=all">

<script type="text/javascript">
	//document.write("Hello World!");
	function maketoday() {
		document.mainform.updateDate.value = document.mainform.tempDate.value;
		//document.mainform.updateDate.color = "#000088";
	}
	function makeNow(destination_field) {
		//var text_now = "<?=date('Y-m-d H:i:s', time())?>";
		var text_now = "<?=date('Y-m-d H:i', time())?>";
		destination_field.value = text_now;
	}
</script>

<style type="text/css">

	@import url('rec.css?<?=$CSS_VERSION?>');

	body {
		-webkit-text-size-adjust: none;
	}

</style>
</head>

<body>

<div style="float:right;">
	<?=UserAccount::AccountNavHtml()?>
</div>


<h1 style="margin-bottom:10px;">
	<img src="images/logo02b.jpg" align="middle" border="0"/> <?=SiteConst('site_name')?>
</h1>

	
<table style="margin:0;">
<tr>
<td style="padding-right:10px;">

	<!--<h6 style="margin:30px 0 5px;">Welcome to <?=SiteConst('site_name')?>:</h6>-->

	<!--<div style="margin:5px 0; font-size:140%; font-weight:bold;">
		&#x00BB; Discover new music from your friends
	</div>
	<div style="margin:20px 0; font-size:140%; font-weight:bold;">
		&#x00BB; Recommend and discuss music, with all
	</div>-->
	<div style="margin:5px 0; font-size:140%; font-weight:bold;">
		&#x00BB; Recommend &amp; discuss music, mini-music-blog style
	</div>
	<div style="margin:20px 0; font-size:140%; font-weight:bold;">
		&#x00BB; Get recommendations from your friends
	</div>


	<div class="inset_box" style="margin-bottom:20px; font-size:100%; font-style:italic;">
		<b>What is this site:</b>
		<div style="margin-top:5px;">
			&bull; On this site you can recommend music to your friends (through your own personal music recommendation feed), and discover new music by seeing what your friends have recommended (by subscribing to their feeds, through email or rss).
		</div>
		<div style="margin-top:9px;">
			&bull; This is not a music sharing site.&nbsp; We presume that users can find any recommended music on their own.&nbsp; (There are currently <a href="http://en.wikipedia.org/wiki/Rhapsody_%28online_music_service%29">various</a> <a href="http://free.napster.com/">legal</a> <a href="http://www.publiclibraries.com/">options</a> for access to great wealths of music.)&nbsp; Where recommendations are legally available on the internet, we encourage posters to link to these places.
		</div>
		<div style="margin-top:9px;">
			&bull; Essential to this site is the conversation of recommending music.  Users have the option to be notified (by rss or by email) when their friends recommend music.  So you'll know immediately - without having to constantly check back at this site - when your friends recommend something new.
		</div>
		<!--<div style="margin-top:9px;">
			&bull; This site relies somewhat on an external <a href="http://en.wikipedia.org/wiki/List_of_feed_aggregators">rss</a> <a href="http://www.google.com/reader/">feed</a> <a href="http://www.bloglines.com/">reader</a> to notify you when new music is recommended to you (not required, but helpful to use the site to its fullest).
		</div>-->
	</div>

	<div class="inset_box">
		<script type="text/javascript" language="javascript" src="http://www.quicktopic.com/41/BThTnDBrGYA97.js"></script>
		<a href="http://www.quicktopic.com/41/H/BThTnDBrGYA97">General forum</a>
		<script type="text/javascript" language="javascript">
		document.write("(" + ct_41_BThT + ")");
		</script>
		| <a href="http://groups.google.com/group/mediarecommend-devel">Development forum</a>
	</div>

	<?//---------------------
	// Recent recommendations
	//-----------------------
	$rec_ar = Recommendation::GetRecArray("all", $PAGE_LENGTH, $page-1, true, $row_count);

	?>
	
	<h6 style="margin-top:20px;">Recent recommendations:</h6>
	<?$i = 0;
	foreach ($rec_ar as $rec_r) {
		$i++;?>
		<div class="rec_class" id="rec<?=$rec_r['recID']?>">
			<div style="font-weight:bold;"><?=htmlentities($rec_r['recText'])?></div>
			<div><?=Recommendation::DescriptionHtml($rec_r['description'])?></div>
			<div class="rec_info">
				<span class="rec_heading"><?=date("Y-m-d", strtotime($rec_r["addedDateTime"]))?></span>
				by
				<?if ($rec_r['userIconPath'] != "") {
					echo "<a href='user.php?user=" . $rec_r['username'] . "'><img src='image.php?usericon=" . $rec_r['userIconPath'] . "&amp;size=16' align='ABSMIDDLE' style='border:solid 1px #aaa; padding:1px;'/></a>";
				}?>
				<a href="user.php?user=<?=$rec_r['username']?>"><?=htmlentities($rec_r['username'])?></a>
				&nbsp; &nbsp;<a href="rec.php?recID=<?=$rec_r['recID']?>"><?=$rec_r['comment_count']?> comments</a>
			</div>
		</div>
	<?}

	// Page links
	echo "Page: ";
	$page_count = ceil($row_count/$PAGE_LENGTH);
	for ($i=0; $i<$page_count; $i++) {
		$temp_page_number = $i+1;
		if ($temp_page_number == $page)
			echo "<b>" . $temp_page_number . "</b> &nbsp;";
		else
			echo "<a href='?page=" . $temp_page_number . "'>" . $temp_page_number . "</a> &nbsp;";
	}?>


</td>
<td id="side_menu">
	<!--<ul>
		<li><a href="./">Back to <?=SiteConst('site_name')?></a></li>
		<li><a href="#add_rec">Add new recommendation</a></li>
	</ul>-->
	

	<hr />
	<form name="add_form" method="post" action="login.php">
		<div style="margin:10px 0;">
			<?if ($auth->AuthenticatedUser() != "") {?>
				Logged in as <i><?=$auth->AuthenticatedUser()?></i>.&nbsp;
				[<a href="login.php?logout=on">Logout</a>]

				<hr />
				<ul>
					<li style="list-style-image: url('images/my_home01.png');"><a href="user.php?user=<?=$auth->AuthenticatedUser()?>">My recommendation page</a></li>
				</ul>

			<?}
			else {?>
				<h5>Login:</h5>
				<table>
				<tr>
					<td>Username:</td>
					<td>
						<input type="text" name="username" value="" style="width:100px;">
					</td>
				</tr>
				<tr>
					<td>Password:</td>
					<td>
						<input type="password" name="password" value="" style="width:100px;">
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
						<input type="submit" name="submit" value="Log in">
						<div style="margin-top:5px;">
							<a href="createuser1.php">Create account</a>
						</div>
					</td>
				</tr>
				</table>
			<?}?>
		</div>
	</form>

	<hr/>

	<h6 style="margin-top:20px;">Users:</h6>
	<?
	$user_ar = $dbobj->GetResultsAsNestedArray("SELECT username, COUNT(*) AS rec_count " .
		"FROM mr_recommendation rec WHERE rec.disabled = 0 GROUP BY username ORDER BY username", 500);
	
	$i = 0;
	foreach ($user_ar as $user_r) {
		$i++;?>
		<div>
			&bull; <a href="user.php?user=<?=$user_r["username"]?>"><?=$user_r["username"]?></a> (<?=$user_r["rec_count"]?>)
		</div>
	<?}?>


</td>
</tr>
</table>




<!--
<table>
<tr>
<td>
	On this site you can recommend music to your friends (through your own personal music recommendation feed), and discover new music by seeing what your friends have recommended (by subscribing to their feed).

	test text 1
</td>
<td style="width:180px;">
	On this site you can recommend music to your friends (through your own personal music recommendation feed), and discover new music by seeing what your friends have recommended (by subscribing to their feed).

	test text 2
</td>
</tr>
</table>
-->



<hr />

<div style="text-align:center; margin:20px auto;">
	<a href="http://code.google.com/p/mediarecommend/"><img src="images/poweredby_mediarecommend.png" style="border-width:0;"/></a>
</div>




<?if ($delete_mode) {?>
	<script type="text/javascript">
	alert("You are in update remove mode.  Please remove inappropriate updates using the checkboxes next to each update (if any).  Removed updates will only appear in remove-mode, and will eventually be read by a moderator.  They will then be deleted forever, or return here perminently.  Thanks for your help.");
	</script>
<?}?>


<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1061881-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</body>
</html>
